import java.util.Random;

//选择排序
public class selectSort
{
    public static void main(String[] args)
    {
        int[] arr = getRandomArray(20);
        for (int i : arr)
        {
            System.out.print(i + " ");
        }
        System.out.println();
        selectSort(arr);
        for (int i : arr)
        {
            System.out.print(i + " ");
        }
    }

    public static int[] selectSort(int[] arr)
    {
        int min = 0, temp = 0, j = 0;
        for (int i = 0; i < arr.length; i++)
        {
            min = arr[i];
            temp = i;
            for (j = i + 1; j < arr.length; j++)
            {
                if (arr[j] < min)
                {
                    min = arr[j];
                    temp = j;
                }
            }
            arr[temp] = arr[i];
            arr[i] = min;
        }
        return arr;
    }

    public static int[] getRandomArray(int n)
    {
        int[] arr = new int[10];
        for (int i = 0; i < 10; i++)
        {
            arr[i] = (int) (Math.random() * n + 1);
        }
        return arr;
    }
}
